﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.ComponentModel;
using System.IO;

namespace Lib.Update
{
    public class Client
    {
        public delegate void ProgressChangedHandler(int Value, bool Done);
        public event ProgressChangedHandler ProgressChanged;

        BackgroundWorker worker = new BackgroundWorker();

        public string ServerPath { get; set; }
        
        public Client()
        {
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.WorkerReportsProgress = true;
            worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
        }

        void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            SetProgressValue(100, true);
        }

        void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            SetProgressValue(e.ProgressPercentage, false);
        }

        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Directory.Exists(ServerPath))
            {
 
            }
        }

        private void CheckAndCopy()
        {
 
        }

        private void SetProgressValue(int value, bool done)
        {
            if (ProgressChanged != null)
                ProgressChanged(value, done);
        }

        public void RunUpdate()
        {
            worker.RunWorkerAsync();
        }
    }
}
